home *** CD-ROM | disk | FTP | other *** search
- Path: news.campus.mci.net!usenet
- From: Kevin Wilson <kevinw@telis.org>
- Newsgroups: comp.lang.c++
- Subject: Derived class question
- Date: Sat, 16 Mar 1996 23:27:06 -0800
- Organization: MCI State Government and University Systems
- Message-ID: <314BBECA.905@telis.org>
- NNTP-Posting-Host: s22-pm04.usc.campus.mci.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- Hi all,
- I could use some help on a program I am writing for homework in a data structures class.
- I am using this class as an excuse to learn c++.
-
- The first class below is for link-list handling and it works fine. My next task was to
- build a routine to implement stacks and one for queues. I was planning on using the
- llist class as a base for a stack class (see below). I get a compile error about type
- conversion...Pop needs to return a Stack *. I have tried several ideas, including
- typing *ptr as a Stack instead of a Llist. But that moves the error to the Retreive
- call. I can work around it by making the char *str public in Llist, but that defeats
- the purpose of protecting the strucure of Llist right?
-
- Whats wrong with this picture?? I havent found any similar examples in my books.
-
- Would really appreciate some help, via email preferred
- Kevin
-
- kevinw@telis.org
-
- BTW, would also appreciate any comments on my methods... anything done here thats REALLY
- Stupid???
-
-
- --------------------------llist.h--------------------------
- #define NULL 0
-
- class Llist{
- private:
- char *str; //points to list element
- Llist *nxt; //points to next element in list
- static Llist head; //list head
- static int nvals; //holds number of elements in list
- public:
- Llist();
- Llist(char *x, Llist *ptr);
- ~Llist();
- int Insert(char *x, int p);
- int Locate(char *x);
- Llist *Retreive(int p);
- int Delete(int p);
- int First();
- int Next(int p);
- int Previous(int p);
- int Last();
- int End();
- int MakeNull();
- void PrintList();
- friend ostream& operator<<(ostream& os, Llist& L);
- };
-
- --------------------------stack.h--------------------------
- //
- // Stack lib using link list class as base
- //
-
- #include "llist.h"
-
- class Stack:public Llist {
- public:
- Stack(void);
- ~Stack();
- char *Pop(void);
- int Push(char *);
- };
-
- --------------------------stack.cpp--------------------------
- #include <iostream.h>
- #include "stack.h"
-
- Stack::Stack():Llist()
- {}
- Stack::~Stack(){}
-
- Stack *Stack::Pop()
- {
- Llist *ptr;
-
- ptr = Retreive(1);
- if(ptr != NULL)
- Llist::Delete(1);
- }
- return ptr; <<<<<<<<<<<<<<<<<<<ERROR
- }
-
- int Stack::Push(char *x)
- {
- return Llist::Insert(x, 1);
- }
-